package com.lagou.homework;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class HomeworkDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(HomeworkDriver.class);

        job.setMapperClass(HomeworkMapper.class);
        job.setReducerClass(HomeworkReducer.class);

        job.setMapOutputKeyClass(Bean.class);
        job.setMapOutputValueClass(NullWritable.class);

        job.setOutputKeyClass(Bean.class);
        job.setOutputValueClass(NullWritable.class);

        job.setOutputFormatClass(HomeworkOutputFormat.class);

        FileInputFormat.setInputPaths(job, new Path("F:\\homework_input"));
        FileOutputFormat.setOutputPath(job, new Path("F:\\homework_output"));

        boolean flag = job.waitForCompletion(true);
        System.exit(flag? 0:1);
    }
}
